package com.jdkreader.concurrency.concurrent.priority;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class EndSentinel extends PrioritizedTask{

    private ExecutorService exec;

    public EndSentinel(ExecutorService service) {
        //终结任务给予最低优先级，最后执行终结操作
        super(-1);
        exec=service;
    }

    @Override
    public void run() {
        int count=0;
        for(PrioritizedTask pt:sequeue){
            System.out.println(pt.summary());
            //换行
            if(++count % 5 == 0){
                System.out.println();
            }
        }

        System.out.println(this+" Calling shutdownNow");
        exec.shutdownNow();
    }
}
